package com.lin.linchatgpt.utils;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Copyright(C),2022年-2022,霖霖
 *
 * @author 霖霖
 * @version 1.0
 * @date 2023/4/1 17:05
 * @Description
 */
@Data
@ToString
public class LinResult implements Serializable {
    private int code;

    private String message;

    private Map<String, Object> result=new HashMap<>();

    private LinResult(){}

    public static LinResult success(){
        LinResult linResult = new LinResult();
        linResult.setMessage("操作成功");
        linResult.setCode(ResultCode.SUCCESS);
        return linResult;
    }

    public static LinResult error(){
        LinResult linResult = new LinResult();
        linResult.setMessage("操作失败");
        linResult.setCode(ResultCode.ERROR);
        return linResult;
    }

    public LinResult data(String key,Object data){
        this.result.put(key,data);
        return this;
    }
    public LinResult data(Map<String,Object> data){
        this.setResult(data);
        return this;
    }

    public LinResult message(String message){
        this.setMessage(message);
        return this;
    }

    public LinResult code(int code){
        this.setCode(code);
        return this;
    }
}
